﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Example_SeoulOpenAPI.Services;
using Example_SeoulOpenAPI.ViewModels;
using System.Collections.ObjectModel;

namespace Example_SeoulOpenAPI
{
    public partial class ArrivalInfoPage : PhoneApplicationPage
    {
        public ArrivalInfoPage()
        {
            InitializeComponent();
            StationService.ArrivalDownloadCompleted += new StationService.ArrivalDownloadStatus(StationService_ArrivalDownloadCompleted);
        }

        private bool isLine2 = false;

        
        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            StationService.DownloadArrivalsByFrCodeAsync("339", "1", isLine2);
        }

        void StationService_ArrivalDownloadCompleted(Exception errorStatus, System.Collections.ObjectModel.ObservableCollection<ViewModels.Arrival> arrivals)
        {
            if (isLine2)
            {
                ObservableCollection<Line2Arrival> line2arrivals = new ObservableCollection<Line2Arrival>();
                foreach (Arrival arrival in arrivals)
                {
                    line2arrivals.Add(arrival as Line2Arrival);
                }

                ArrivalListBox.ItemsSource = line2arrivals;
            }
            else
            {
                ArrivalListBox.ItemsSource = arrivals;
            }
            
        }

    }
}